<?php
/*由bean脚本生成 powerBy--joe*/
namespace app\common\model;

use app\common\bean\OrderGoodsBean;
use app\common\bean\OrderGoodsDetailBean;
use app\common\bean\StoreBean;
use app\common\bean\UserAddressBean;
use app\common\bean\UserBean;
use app\common\enum\OrderGoodsStatusEnum;

class OrderGoodsModel extends BaseModel
{
	protected $table = 'order_goods';
	protected $append = ['status_text'];

	/**
	* @return OrderGoodsModel
	*/
	static function getInstance(){
		return parent::getInstance();
	}

	public function getStatusTextAttr($value,$data){
	    return OrderGoodsStatusEnum::getName($data[OrderGoodsBean::$status]);
    }

    /**
     * @return \think\model\relation\HasOne
     */
	public function withdetail(){
	    return $this->hasOne('OrderGoodsDetailModel', OrderGoodsDetailBean::$orderGoodsId,OrderGoodsBean::$id);
    }

    public function withstore(){
        return $this->belongsTo('StoreModel',OrderGoodsBean::$storeId,StoreBean::$id);
    }
    public function withuser(){
        return $this->belongsTo('UserModel',OrderGoodsBean::$userId,UserBean::$id);
    }

    /**
     * 关联用户的地址
     * @return \think\model\relation\HasOne
     */
    public function userAddress(){
        return $this->hasOne("UserAddressModel",UserAddressBean::$id,OrderGoodsBean::$userAddressId);
    }

    /**
     * @return \think\model\relation\HasOne
     */
    public function orderDetails(){
        return $this->hasMany('OrderGoodsDetailModel', OrderGoodsDetailBean::$orderGoodsId,OrderGoodsBean::$id);
    }
}
